import request from '@/utils/request';

// 表格数据渲染
export function list(params: any) {
    return request({
        method: "get",
        url: "/tienchin/business/list",
        params
    })
}
// 新增
export function add(data: any) {
    return request({
        method: "post",
        url: "/tienchin/business",
        data
    })
}
// // 新增选项框中下拉列表
// export function under(id: number) {
//     return request({
//         method: "get",
//         url: "/tienchin/business/activity",
//          params: { id }
//     })
// }
// 删除
export function clueDel(ids: number | number[]) {
    if (Array.isArray(ids)) {
        // 过滤掉 undefined/null/非数字
        const validIds = ids.filter(id => typeof id === 'number' && !isNaN(id));
        return Promise.all(validIds.map(id => request({
            url: `/tienchin/business/${id}`,
            method: 'delete',
        })));
    } else if (typeof ids === 'number' && !isNaN(ids)) {
        // 单个删除且为有效数字
        return request({
            url: `/tienchin/business/${ids}`,
            method: 'delete',
        });
    } else {
        // 非法 id 直接返回 rejected Promise
        return Promise.reject(new Error('无效的 id'));
    }
}
// 修改
export function updata(data: any) {
    return request({
        method: "put",
        url: "/tienchin/business",
        data
    })
}
// 详情接口
export function detail(id: number) {
    return request({
        method: "get",
        url: "/tienchin/business/summary/" + id,
    })
}
// 分配商机下拉框
export function getBusinessOptions(id: number) {
    return request({
        method: "get",
        url: "/tienchin/clue/users/" + id,
    })
}
export function xiangqing(params: number) {
    return request({
        method: "get",
        url: "/system/dept/treeselect",
        params
    })
}
// 渠道来源接口   
export function channelSource(params: number) {
    return request({
        method: "get",
        url: "/tienchin/business/channels",
        params
    })
}
// 活动信息接口
export function activityInfo(params: number) {
    return request({
        method: "get",
        url: "/tienchin/business/activity" + params,
        params
    })
}
// 线索分配接口
export function clueAssign(data: any) {
    return request({
        method: "post",
        url: "/tienchin/assignment",
        data
    })
}